<script setup>
  import {ref,onMounted,onUnmounted} from 'vue'
  import { useRouter } from 'vue-router'
  const router = useRouter()
  const showBackToTop = ref(false)
  import {Iphone,Search,ShoppingCart,ArrowUpBold} from '@element-plus/icons-vue'
  const pic = [
    { url:"/src/assets/pic/topic1.png",title:'topic1',id : 1 },
    { url:"/src/assets/pic/topic2.png",title:'topic2',id : 2 },
    { url:"/src/assets/pic/topic3.png",title:'topic3',id : 3 }
  ]
  const pict = ref(null)
  const p = ref(null)

  let i = 0
  // 轮播逻辑
  let interval
  onMounted(() => {
   setInterval(() => {
      pict.value.src = pic[i].url
      i++
      if(i >= pic.length){
        i = 0
      }
    },1000)
  })

  onUnmounted(() => {
    clearInterval(interval)
  })

  const handleScroll = () => {
    const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
    showBackToTop.value = scrollTop > 10
  }

  const scrollToTop = () => {
    window.scrollTo({
      top:0,
      behavior:'smooth'
    })
  }

  // 生命周期钩子，添加和移除滚动监听
  onMounted(()=> {
    window.addEventListener('scroll',handleScroll)
  })

  onUnmounted(() => {
    window.removeEventListener('scroll',handleScroll)
  })




</script>
<template>
  <div class="wrapper">
    <div class="shortcut">
      <ul>
        <li><el-link @click="router.push('/login')" class="login">请先登录  |</el-link></li>
        <li><el-link @click="router.push('/register')">免费注册  |</el-link></li>
        <li><el-link href="#">我的订单  |</el-link></li>
        <li><el-link @click="router.push('/drink')">新闻列表  |</el-link></li>
        <li><el-link href="#"> <el-icon><Iphone /></el-icon>手机版</el-link></li>
      </ul>
    </div>

  <div class="hb">
        <!-- 头部 -->
  <div class="header">
    <!-- 导航 -->
    <div class="nav">
          <el-menu :default-active="activeIndex" class="menu" mode="horizontal" @select="handelSelect">
            <el-sub-menu class="sub-menu" index="1">
              <template #title>食品</template>
              <el-menu-item index="1-1">粮油速食</el-menu-item>
              <el-menu-item index="1-2">休闲零食</el-menu-item>
              <el-menu-item index="1-3">乳品冲饮</el-menu-item>
              <el-menu-item index="1-4">饼干糕点</el-menu-item>
            </el-sub-menu>
            <el-sub-menu class="sub-menu" index="2">
              <template #title>货物</template>
              <el-menu-item index="2-1">个人护理</el-menu-item>
              <el-menu-item index="2-2">百货</el-menu-item>
              <el-menu-item index="2-3">百货</el-menu-item>
              <el-menu-item index="2-4">百货</el-menu-item>
            </el-sub-menu>
            <el-sub-menu class="sub-menu" index="3">
              <template #title>鞋包</template>
              <el-menu-item index="3-1">女鞋</el-menu-item>
              <el-menu-item index="3-2">男鞋</el-menu-item>
              <el-menu-item index="3-3">低帮鞋</el-menu-item>
              <el-menu-item index="3-4">春上新</el-menu-item>
            </el-sub-menu>
            <el-sub-menu class="sub-menu" index="4">
              <template #title>美妆</template>
              <el-menu-item index="4-1">水乳面霜</el-menu-item>
              <el-menu-item index="4-2">护肤套装</el-menu-item>
              <el-menu-item index="4-3">彩妆</el-menu-item>
              <el-menu-item index="4-4">面部清洁</el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="5">
              <template #title>水果</template>
              <el-menu-item index="5-1">水果及制品</el-menu-item>
              <el-menu-item index="5-2">瓜果桃梨枣</el-menu-item>
              <el-menu-item index="5-3">热带水果</el-menu-item>
              <el-menu-item index="5-4">蔬菜及制品</el-menu-item>
            </el-sub-menu>
          </el-menu>
    </div>
    <!-- 搜索 -->
    <div class="search">
      <el-input type="text" placeholder="搜索" :prefix-icon="Search"></el-input>
    </div>
  </div>

  <!-- banner -->
  <div class="banner">
    <div class="slider-container" >
      <img class="slider" ref="pict" style="width:100%;height:500px" :src="pic[0].url" alt="">
    </div>

  </div>
  <!-- 新鲜好物 -->
  <div class="goods">
    <!-- 标题 -->
    <div class="title">
      <div class="left">
        <h3>新鲜好物</h3>
        <p>新鲜出炉，品质靠谱</p>
      </div>
      <div class="right">
        <a href="#" class="more">查看全部 > </a>
      </div>
    </div>

          <!-- 内容 -->
    <div class="bd">
      <ul>
        <li>
          <a href="#">
            <div class="pic"><img src="@/assets/uploads/goods1.png" alt=""></div>
            <div class="txt">
              <h4>奥斯那斯牛奶口罩</h4>
              <p>￥<span>79</span></p>
            </div>
          </a>
        </li>
        <li>
          <a href="#">
            <div class="pic"><img src="@/assets/uploads/goods3.png" alt=""></div>
            <div class="txt">
              <h4>阿尔卑斯普洱茶盒</h4>
              <p>￥<span>566</span></p>
            </div>
          </a>
        </li>
        <li>
          <a href="#">
            <div class="pic"><img src="@/assets/uploads/goods4.png" alt=""></div>
            <div class="txt">
              <h4>阿尔卑斯高级沙发</h4>
              <p>￥<span>58</span></p>
            </div>
          </a>
        </li>
        <li>
          <a href="#">
            <div class="pic"><img src="@/assets/uploads/goods1.png" alt=""></div>
            <div class="txt">
              <h4>罗马尼亚高级沙发</h4>
              <p>￥<span>3579</span></p>
            </div>
          </a>
        </li>
      </ul>
    </div>
  </div>


  <!-- 热门推荐 -->
  <div class="fresh">
  <!-- 标题 -->
    <div class="title">
    <div class="left">
      <h3>生鲜</h3>

    </div>
      <div class="right">
      <ul>
        <li><a href="#" class="active">热门</a></li>
        <li><a href="#">蔬菜</a></li>
        <li><a href="#">肉禽蛋</a></li>
        <li><a href="#">水果</a></li>
        <li><a href="#">海鲜</a></li>
        <li><a href="#">零食</a></li>
        <li><a href="#">饮料</a></li>
      </ul>
      <a href="#" class="more">查看全部 > </a>
     </div>
    </div>
    <!-- 内容 -->
    <div class="content">
      <div class="left">
        <a href="#"><img src="@/assets/uploads/fresh_left.png" alt=""></a>
      </div>
      <div class="right">
        <ul>
          <li>
            <a href="#">
            <div class="pic"><img src="@/assets/uploads/fresh1.png" alt=""></div>
            <div class="txt">
              <div class="info">
                <h4>双味千层,手抓饼烤肉组合</h4>
                <p>240g/袋 4片装</p>
                <p>加热即使</p>
              </div>
              <p class="price">￥<span>89.99</span></p>
            </div>
            </a></li>
          <li><a href="#">
            <div class="pic"><img src="@/assets/uploads/fresh2.png" alt=""></div>
            <div class="txt">
              <div class="info">
                <h4>云南甘蔗慢熬红糖馒头</h4>
                <p>220g/袋 5个装</p>
                <p>加热即使</p>
              </div>
              <p class="price">￥<span>9.00</span></p>
            </div>
          </a></li>
                  <li><a href="#">
                    <div class="pic"><img src="@/assets/uploads/fresh3.png" alt=""></div>
                    <div class="txt">
                      <div class="info">
                        <h4>日式风味小圆饼</h4>
                        <p>圆形【海盐味】</p>
                        <p>糖果零食</p>
                      </div>
                      <p class="price">￥<span>588.00</span></p>
                    </div>
                  </a></li>
                  <li><a href="#">
                    <div class="pic"><img src="@/assets/uploads/fresh3.png" alt=""></div>
                    <div class="txt">
                      <div class="info">
                        <h4>日式风味小圆饼</h4>
                        <p>圆形【海盐味】</p>
                        <p>糖果零食</p>
                      </div>
                      <p class="price">￥<span>588.00</span></p>
                    </div>
                  </a></li>
                  <li><a href="#">
                    <div class="pic"><img src="@/assets/uploads/fresh4.png" alt=""></div>
                    <div class="txt">
                      <div class="info">
                        <h4>全买奶油浓香小面包</h4>
                        <p>5g * 12 袋</p>
                        <p>美味西点</p>
                      </div>
                      <p class="price">￥<span>69.00</span></p>
                    </div>
                  </a></li>
                  <li><a href="#">
                    <div class="pic"><img src="@/assets/uploads/fresh5.png" alt=""></div>
                    <div class="txt">
                      <div class="info">
                        <h4>秘制外皮五福摩提大福点心</h4>
                        <p>、150g / 盒</p>
                        <p>美味西点</p>
                      </div>
                      <p class="price">￥<span>39.99</span></p>
                    </div>
                  </a></li>
                  <li><a href="#">
                    <div class="pic"><img src="@/assets/uploads/fresh6.png" alt=""></div>
                    <div class="txt">
                      <div class="info">
                        <h4>水果面膜韩国蜂蜜柚子茶</h4>
                        <p>圆形【海盐味】</p>
                        <p>糖果零食</p>
                      </div>
                      <p class="price">￥<span>588.00</span></p>
                    </div>
                  </a></li>
                  <li><a href="#">
                    <div class="pic"><img src="@/assets/uploads/fresh7.png" alt=""></div>
                    <div class="txt">
                      <div class="info">
                        <h4>浓情比利时巧克力礼盒装</h4>
                        <p>205克 / 盒</p>
                        <p>糖果零食</p>
                      </div>
                      <p class="price">￥<span>120.00</span></p>
                    </div>
                  </a></li>
                </ul>
              </div>
            </div>
        </div>

  <!-- 底部 -->
  <div class="footer">
    <!-- 服务 -->
    <div class="service">
      <ul>
        <li>
          <h5></h5>
          <p>价格亲民</p>
        </li>
        <li>
          <h5></h5>
          <p>物流快捷</p>
        </li>
        <li>
          <h5></h5>
          <p>售后无忧</p>
        </li>
        <li>
          <h5></h5>
          <p>品质新鲜</p>
        </li>
      </ul>
    </div>
    <!-- 帮助中心 -->
    <div class="help">
      <div class="left">
        <dl>
          <dt>购物指南</dt>
          <dd><a href="#">购物流程</a></dd>
          <dd><a href="#">支付方式</a></dd>
          <dd><a href="#">售后规则</a></dd>
        </dl>
        <dl>
          <dt>配送方式</dt>
          <dd><a href="#">配送运费</a></dd>
          <dd><a href="#">配送范围</a></dd>
          <dd><a href="#">配送时间</a></dd>
        </dl>
        <dl>
          <dt>关于我们</dt>
          <dd><a href="#">平台规则</a></dd>
          <dd><a href="#">联系我们</a></dd>
          <dd><a href="#">问题反馈</a></dd>
        </dl>
        <dl>
          <dt>售后服务</dt>
          <dd><a href="#">售后政策</a></dd>
          <dd><a href="#">退款说明</a></dd>
          <dd><a href="#">取消订单</a></dd>
        </dl>
        <dl>
          <dt>服务热线</dt>
          <dd><a href="#">在线客服 <span class="iconfont icon-customer-service"></span></a></dd>
          <dd><a href="#">客服电话 400-0000-000</a></dd>
          <dd><a href="#">工作时间 周一至周日 8:00 - 18:00</a></dd>
        </dl>
      </div>
    </div>
  </div>

   <!-- 滚动框 -->
   <div v-if="showBackToTop" class="back-to-top" @click="scrollToTop" >
    <el-icon :size="40"  color="black" ><ArrowUpBold /></el-icon>
    回到顶部
    </div>

    </div>
  </div>
</template>
<style lang="scss" scoped>
.wrapper{
  margin: 0 auto;
  width: 1616px;
  box-sizing: border-box;
  .shortcut{
    background-color: #fff;
    height: 150px;
    margin-bottom: 5px;
    padding-top: 50px;
    position:fixed;
    top: 0;
    right: 0px;
    left: 0;
    padding-right: 250px;
    overflow: hidden;
    z-index: 999;
    ul{
      list-style: none;
      display: flex;
      justify-content: flex-end;
      li{
        padding-right: 8px;
        color: #fff;
        line-height: 52px;
        font-size: 14px;
        font-weight: 700;
        :deep(.el-link){
          font-size: 20px;
          &:hover{
            text-decoration: none !important;
          }
          .el-icon{
            vertical-align: middle;
          }
        }
      }
    }
  }
  .hb{
    position: relative;
    top:200px ;
    .header{
    margin-top: 22px;
    margin-bottom: 22px;
    margin-left: 20px;
    height: 88px;
    display: flex;
    align-items: center;
    .nav{
      flex: 1;
      :deep(.el-menu--horizontal){
        .el-sub-menu__title{
           font-size: 25px;
        }
        .el-menu-item{
          font-size: 25px;
          &:hover{
            background-color: #00BE9A;
          }
        }
      }

  }
}
//       :deep(.el-sub-menu__title){
//         font-size: 25px;
//         :deep(.el-menu--horizontal .el-menu-item) {
//           font-size: 20px;
// }
//       }
//       :deep(.el-sub-menu__title) {
//         @media (max-width: 768px) {
//           font-size: 24px !important;
//   }
// }


  .banner .wrapper{
    position: relative;
    height: auto;
    overflow: hidden;
    .slider-container{
      width: 100%;
      position: relative;
      .slider{
        width: 100%;
        height: 500px;
    }
    }
    .slider-footer{
      position: absolute;
      bottom: 10px;
      right: 10px;
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      .pic{
        display: flex;
        list-style: none;
        margin: 0;
        padding: 0;
      }
      li{
        width: 10px;
        height: 10px;
        background-color: gray;
        border-radius: 50%;
        margin: 0 5px;
        & .active{
          background-color: white;
        }
      }
    }

  }

  .goods{
    .title{
      height: 42px;
      // background-color: pink;
      display: flex;
      justify-content: space-between;
      margin-top: 40px;
      margin-bottom: 30px;
      .left{
        display: flex;
        align-items: center;
        flex:1;
        h3{
          margin-right: 35px;
          font-size: 30px;
        }
      }
    }
    .bd{
         ul{
        display: flex;
        justify-items: start;
        justify-content: space-between;
        // ul 默认有左内外边距，这里去掉
        list-style: none;
        margin-left: 0;
        padding-left: 0;
        li{
        width: 380px;
        height: 404px;
        background-color: #EEF9F4;
        img{
          width: 380px;
          height: 304px;
          }
        .txt{
          text-align: center;
          h4{
            margin-top: 18px;
            margin-bottom: 8px;
            font-size: 20px;
          }
          p{
            font-size: 18px;
            span{
              margin-left: 3px;
              font-size: 22px;
            }
          }
        }
      }
        }

    }
    }

    }


  .fresh{
    .title{
      display: flex;
      margin-top: 60px;
      margin-block: 20px;
      .left{
        flex: 1;
      }
      .right{
        display: flex;
        align-items: center;
        ul{
          display: flex;
          margin-top: 10px;
          margin-right: 58px;
          list-style: none;
          li{
            margin-right: 20px;
            cursor: pointer;
            .active{
              background-color: #00BE9A;
              color:#fff ;
            }
          }
        }
      }
    }
    .content{
      display: flex;
      justify-content: space-between;
      .left{
        padding-top: 10px;
        margin-right: 20px;
        img{
          height: 800px;
        }
      }
      .right{
        // width: 969px;
        // height: 610px;
        ul{
          display: flex;
          margin-left: 0;
          padding: 0;
          list-style: none;
          flex-wrap: wrap;
          justify-content: space-between;
          li{
            background-color: #EEF9F4;
            margin-bottom: 20px;
            img{
              width: 300px;
              height: 200px;
            }
          }
        }
      }
    }


  }

  .footer{
    height: 580px;
    background-color: #E8E8E8;
    .service{
      padding: 60px 0;
      // height: 100px;
      border-bottom: 1px solid #E8E8E8;
      ul{
        display: flex;
        justify-content: space-evenly;
        li{
          display: flex;
          align-items: center;
          width: 190px;
          height: 58px;
          h5{
            margin-right: 20px;
            width: 58px;
            height: 58px;
            background-image: url(src/assets/images/sprite.png);
          }
          p{
            font-size: 28px;
            line-height: 58px;
          }
        }
      }
    }
    .help{
      display: flex;
      justify-self: space-between;
      padding-top: 60px;
      // height: 300px;
      .left{
        display: flex;
        dl{
          margin-right:80px;
          dl:last-child{
            margin-right: 0;
          }
          dt{
            margin-bottom: 40px;
            margin-left: 30px;
            font-size: 18px;
            // text-align: left;
          }
          dd{
            margin-bottom: 16px;
            font-size: 14px;
            // text-align: left;
          }
        }
      }
    }
  }

  .back-to-top{
      position: fixed;
      bottom:500px ;
      right: 100px;
      width: 100px;
      height: 100px;
      // background-color: green;
      color: black;
      border-radius: 15%;
      display: flex;
      align-items: center;
      justify-self: center;
      cursor: pointer;
      font-size: 23px;
      box-shadow:0 2px 10px rgba(0, 0, 0, 0.2) ;
      transition: opacity 0.3s ease;
      &:hover{
        background-color: rgba(194, 41, 41, 0.116);
      }

    }



  }

</style>
